#include <QtGui/QApplication>
#include <QtConcurrentMap>
#include <QList>
#include "math.h"
#include <QDebug>

double left_ = 0.0;
double right_ = 3.14;
int parts = 100;

double sinOnInterval(double x)
{
    return sin(x) * (right_ - left_) / parts;
}

void sumOfResults(double& result, const double & x)
{
    result += x;
}

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QList<double> points;

    for(size_t i = 0; i < parts; ++i)
    {
        points.push_back(i * (right_ - left_) / parts);
    }

    QFuture<double> result = QtConcurrent::mappedReduced(points, sinOnInterval, sumOfResults);

    result.waitForFinished();
    qDebug() << result.result();
    return a.exec();
}


